package cn.ibizlab.odoo.core.odoo_gamification.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.math.BigInteger;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Lazy;
import cn.ibizlab.odoo.core.odoo_gamification.domain.Gamification_challenge_line;
import cn.ibizlab.odoo.core.odoo_gamification.filter.Gamification_challenge_lineSearchContext;
import cn.ibizlab.odoo.core.odoo_gamification.service.IGamification_challenge_lineService;

import cn.ibizlab.odoo.util.helper.CachedBeanCopier;



import cn.ibizlab.odoo.core.odoo_gamification.client.gamification_challenge_lineOdooClient;
import cn.ibizlab.odoo.core.odoo_gamification.clientmodel.gamification_challenge_lineClientModel;

/**
 * 实体[游戏化挑战的一般目标] 服务对象接口实现
 */
@Slf4j
@Service
public class Gamification_challenge_lineServiceImpl implements IGamification_challenge_lineService {

    @Autowired
    gamification_challenge_lineOdooClient gamification_challenge_lineOdooClient;


    @Override
    public boolean remove(Integer id) {
        gamification_challenge_lineClientModel clientModel = new gamification_challenge_lineClientModel();
        clientModel.setId(id);
		gamification_challenge_lineOdooClient.remove(clientModel);
        return true; 
    }

    public void removeBatch(Collection<Integer> idList){
    }

    @Override
    public boolean create(Gamification_challenge_line et) {
        gamification_challenge_lineClientModel clientModel = convert2Model(et,null);
		gamification_challenge_lineOdooClient.create(clientModel);
        Gamification_challenge_line rt = convert2Domain(clientModel,null);
        if(rt==null)
            return false;
        CachedBeanCopier.copy(rt,et);
        return true;
    }

    public void createBatch(List<Gamification_challenge_line> list){
    }

    @Override
    public Gamification_challenge_line get(Integer id) {
        gamification_challenge_lineClientModel clientModel = new gamification_challenge_lineClientModel();
        clientModel.setId(id);
		gamification_challenge_lineOdooClient.get(clientModel);
        Gamification_challenge_line et = convert2Domain(clientModel,null);
        if(et==null){
            et=new Gamification_challenge_line();
            et.setId(id);
        }
        else{
        }

        return  et;
    }

    @Override
    public boolean update(Gamification_challenge_line et) {
        gamification_challenge_lineClientModel clientModel = convert2Model(et,null);
		gamification_challenge_lineOdooClient.update(clientModel);
        Gamification_challenge_line rt = convert2Domain(clientModel,null);
        if(rt==null)
            return false;
        CachedBeanCopier.copy(rt,et);
        return true;

    }
    
    public void updateBatch(List<Gamification_challenge_line> list){
    }





    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Gamification_challenge_line> searchDefault(Gamification_challenge_lineSearchContext context) {
        List<Gamification_challenge_line> list = new ArrayList<Gamification_challenge_line>();
        Page<gamification_challenge_lineClientModel> clientModelList = gamification_challenge_lineOdooClient.search(context);
        for(gamification_challenge_lineClientModel clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_challenge_line>(list, context.getPageable(), clientModelList.getTotalElements());
    }

    public gamification_challenge_lineClientModel convert2Model(Gamification_challenge_line domain , gamification_challenge_lineClientModel model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = new gamification_challenge_lineClientModel();

        }
        if((Boolean) domain.getExtensionparams().get("dirtyflagenable")){
            if((Boolean) domain.getExtensionparams().get("iddirtyflag"))
                model.setId(domain.getId());
            if((Boolean) domain.getExtensionparams().get("target_goaldirtyflag"))
                model.setTarget_goal(domain.getTargetGoal());
            if((Boolean) domain.getExtensionparams().get("write_datedirtyflag"))
                model.setWrite_date(domain.getWriteDate());
            if((Boolean) domain.getExtensionparams().get("__last_updatedirtyflag"))
                model.set__last_update(domain.getLastUpdate());
            if((Boolean) domain.getExtensionparams().get("create_datedirtyflag"))
                model.setCreate_date(domain.getCreateDate());
            if((Boolean) domain.getExtensionparams().get("display_namedirtyflag"))
                model.setDisplay_name(domain.getDisplayName());
            if((Boolean) domain.getExtensionparams().get("sequencedirtyflag"))
                model.setSequence(domain.getSequence());
            if((Boolean) domain.getExtensionparams().get("definition_monetarydirtyflag"))
                model.setDefinition_monetary(domain.getDefinitionMonetary());
            if((Boolean) domain.getExtensionparams().get("conditiondirtyflag"))
                model.setCondition(domain.getCondition());
            if((Boolean) domain.getExtensionparams().get("create_uid_textdirtyflag"))
                model.setCreate_uid_text(domain.getCreateUidText());
            if((Boolean) domain.getExtensionparams().get("write_uid_textdirtyflag"))
                model.setWrite_uid_text(domain.getWriteUidText());
            if((Boolean) domain.getExtensionparams().get("definition_full_suffixdirtyflag"))
                model.setDefinition_full_suffix(domain.getDefinitionFullSuffix());
            if((Boolean) domain.getExtensionparams().get("challenge_id_textdirtyflag"))
                model.setChallenge_id_text(domain.getChallengeIdText());
            if((Boolean) domain.getExtensionparams().get("namedirtyflag"))
                model.setName(domain.getName());
            if((Boolean) domain.getExtensionparams().get("definition_suffixdirtyflag"))
                model.setDefinition_suffix(domain.getDefinitionSuffix());
            if((Boolean) domain.getExtensionparams().get("write_uiddirtyflag"))
                model.setWrite_uid(domain.getWriteUid());
            if((Boolean) domain.getExtensionparams().get("challenge_iddirtyflag"))
                model.setChallenge_id(domain.getChallengeId());
            if((Boolean) domain.getExtensionparams().get("create_uiddirtyflag"))
                model.setCreate_uid(domain.getCreateUid());
            if((Boolean) domain.getExtensionparams().get("definition_iddirtyflag"))
                model.setDefinition_id(domain.getDefinitionId());
            domain.getFocusNull().clear();
        }
        return model ;
    }

    public Gamification_challenge_line convert2Domain( gamification_challenge_lineClientModel model ,Gamification_challenge_line domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Gamification_challenge_line();
        }

        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getTarget_goalDirtyFlag())
            domain.setTargetGoal(model.getTarget_goal());
        if(model.getWrite_dateDirtyFlag())
            domain.setWriteDate(model.getWrite_date());
        if(model.get__last_updateDirtyFlag())
            domain.setLastUpdate(model.get__last_update());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreateDate(model.getCreate_date());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplayName(model.getDisplay_name());
        if(model.getSequenceDirtyFlag())
            domain.setSequence(model.getSequence());
        if(model.getDefinition_monetaryDirtyFlag())
            domain.setDefinitionMonetary(model.getDefinition_monetary());
        if(model.getConditionDirtyFlag())
            domain.setCondition(model.getCondition());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreateUidText(model.getCreate_uid_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWriteUidText(model.getWrite_uid_text());
        if(model.getDefinition_full_suffixDirtyFlag())
            domain.setDefinitionFullSuffix(model.getDefinition_full_suffix());
        if(model.getChallenge_id_textDirtyFlag())
            domain.setChallengeIdText(model.getChallenge_id_text());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getDefinition_suffixDirtyFlag())
            domain.setDefinitionSuffix(model.getDefinition_suffix());
        if(model.getWrite_uidDirtyFlag())
            domain.setWriteUid(model.getWrite_uid());
        if(model.getChallenge_idDirtyFlag())
            domain.setChallengeId(model.getChallenge_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreateUid(model.getCreate_uid());
        if(model.getDefinition_idDirtyFlag())
            domain.setDefinitionId(model.getDefinition_id());
        return domain ;
    }

}

    



